package com.abc.controller;

import com.abc.config.SseEmitterUTF8;
import com.abc.service.ChatGPTService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import org.springframework.web.socket.WebSocketSession;

@RestController
public class ChatGPTController {

    @Autowired
    private ChatGPTService chatGPTService;

    @GetMapping("/spark")
    public SseEmitter chat(@RequestParam String input) {
        SseEmitter emitter = new SseEmitterUTF8(0L); // 设置超时时间为无限
        chatGPTService.chat(input, emitter);
        return emitter;
    }

//    @GetMapping("/ws/chat")
//    public void chat(WebSocketSession session, String input) {
//        chatGPTService.chatWebSocket(input, session);
//    }
}
